// pages/bindingShop/bindingShop.js
var app = getApp();
var com = require('../../common.js')
Page({
  data: {
    sw: true,
    info: {},
    code: '',
    statusd: 1,
    string: ""
  },
  hexiao(e) {
    var _this = this,
      id = e.currentTarget.id
    if (id == 1) {
      wx.showToast({
        title: '该券已作废',
        icon: 'none'
      })
      return false;
    } else {
      wx.showModal({
        title: '温馨提示',
        content: '确定核销吗？',
        success(res) {
          if (res.confirm) {
            if (_this.data.info.service.coupon.is_optometry) {
              var data = _this.data.string
              if (data) {
                data.yy_zd = _this.data.yy_zd
                data.jy_zd = _this.data.jy_zd
                data.code = _this.data.code
              } else {
                wx.showModal({
                  title: '温馨提示',
                  content: '请录入完整验光单',
                })
                return false
              }
            } else {
              var data = {}
              data.code = _this.data.code
            }
            com.link(app.link.checksCode, data, function(rep) {
              console.log(rep)
              if (!rep.data.state) {
                wx.showToast({
                  title: rep.data.message,
                  icon: 'none'
                })
                return
              }
              wx.showToast({
                title: '核销成功',
                icon: 'success'
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1
                })
              }, 1500)
            })
          }
        }
      })
    }


  },
  jumpPage() {
    var _this = this
    if (_this.data.string) {
      let data = _this.data.string
      data.jy_zd = _this.data.jy_zd
      data.yy_zd = _this.data.yy_zd
      wx.navigateTo({
        url: "/pages/entering/entering?string=" + JSON.stringify(data),
      })
    } else {
      wx.navigateTo({
        url: "/pages/entering/entering"
      })
    }
  },
  onLoad: function(options) {
    console.log(options)
    var _this = this,
      i = JSON.parse(options.string)
    _this.setData({
      info: i,
      code: i.code
    })
    setTimeout(() => {
      _this.setData({
        statusd: 0
      })
    }, 1200)
  },
  sweep: function() {
    this.setData({
      sw: false
    })
  },
  onReady: function() {},
  onShow: function() {
    var _this = this
    console.log(_this.data)
  },
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function() {}
})